#include "Light.h"

Light::Light() : m_lightDir(0.0f,-2.0f,1.0f), m_num(0), m_status(false) {}

void Light::Initialize(D3DLIGHTTYPE lightType, float range) {
	m_light.Type			= lightType;
	m_light.Diffuse.r		= m_light.Diffuse.g			= m_light.Diffuse.b  = 1.0f;
	m_light.Specular.r		= m_light.Specular.g		= m_light.Specular.b = 0.1f;
	m_light.Ambient.r		= m_light.Ambient.g			= m_light.Ambient.b  = 0.0f;
	if(lightType == D3DLIGHT_POINT) {
		m_light.Position	= D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	}
	D3DXVec3Normalize((D3DXVECTOR3*)&m_light.Direction, &m_lightDir);
	if(lightType == D3DLIGHT_POINT) {
		m_light.Attenuation0		= m_light.Attenuation1		= m_light.Attenuation2 = 0.0f;
	}
	m_light.Range			= range;
}

void Light::setPosAbs(float x, float y, float z) {
	m_light.Position.x = x;		m_light.Position.y = y;		m_light.Position.z = z;
}

void Light::setAtt(float zero, float one, float two) {
	m_light.Attenuation0 = zero;		m_light.Attenuation1 = one;		m_light.Attenuation2 = two;
}

void Light::setDirAbs(float x, float y, float z) {
	m_lightDir.x = x;		m_lightDir.y = y;		m_lightDir.z = z;
}

void Light::setDirRel(float x, float y, float z) {
	m_lightDir.x += x;		m_lightDir.y += y;		m_lightDir.z += z;
}

void Light::setDifAbs(float r, float g, float b) {
	m_light.Diffuse.r = r;		m_light.Diffuse.g = g;		m_light.Diffuse.b = b;
}

void Light::setDifRel(float r, float g, float b) {
	m_light.Diffuse.r += r;		m_light.Diffuse.g += g;		m_light.Diffuse.b += b;
}

void Light::setSpeAbs(float r, float g, float b) {
	m_light.Specular.r = r;		m_light.Specular.g = g;		m_light.Specular.b = b;
}

void Light::setSpeRel(float r, float g, float b) {
	m_light.Specular.r += r;	m_light.Specular.g += g;	m_light.Specular.b += b;
}

void Light::setAmbAbs(float r, float g, float b) {
	m_light.Ambient.r = r;		m_light.Ambient.g = g;		m_light.Ambient.b = b;
}

void Light::setAmbRel(float r, float g, float b) {
	m_light.Ambient.r += r;		m_light.Ambient.g += g;		m_light.Ambient.b += b;
}

void Light::setLight(LPDIRECT3DDEVICE9 pDevice, int num) {
	m_num = num;
	D3DXVec3Normalize((D3DXVECTOR3*)&m_light.Direction, &m_lightDir);
	pDevice->SetLight(m_num, &m_light);
}

void Light::enableLight(LPDIRECT3DDEVICE9 pDevice, bool status) {
	pDevice->LightEnable(m_num, status);
	m_status = status;
}

bool Light::getStatus() {
	return m_status;
}
D3DLIGHT9* Light::getLight() {
	return &m_light;
}
D3DXVECTOR3* Light::getLightDir() {
	return &m_lightDir;
}
